package com.lxy.u4day0501.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lxy.u4day0501.dao.UserDao;
import com.lxy.u4day0501.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Transactional
@Component
public class UserServiceImpl extends ServiceImpl<UserDao, User> implements UserService{
    @Autowired(required = false)
    private UserDao userDao;

    @Override
    public Map<String, Object> findByLimit(Integer pageNum,Integer PageSize) {
        Map<String,Object> map = new HashMap<>();
        try {
            PageHelper.startPage(pageNum,PageSize);
            List<User> users = userDao.selectList(null);
            PageInfo pageInfo = new PageInfo(users);
            map.put("users",users);
            map.put("code",200);
            map.put("info","成功");
        } catch (Exception e) {
            e.printStackTrace();
            map.put("code",500);
            map.put("info","失败");
        }
        return map;
    }
}
